package edu.zju.gis.dbfg.model.util;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.Map;

public class FormatUtil {
    public static String Shape2GeoJson(Object shapeFromES) {
        JSONObject FeatureCollection = new JSONObject();
        JSONArray features = new JSONArray();
        JSONObject feature = new JSONObject();
        JSONObject geom = new JSONObject();
        Map<String, Object> source = (Map) shapeFromES;
        geom.put("coordinates", new JSONArray(source.get("coordinates").toString()));
        geom.put("type", source.get("type"));
        feature.put("type", "Feature");
        feature.put("properties", new JSONObject());
        feature.put("geometry", geom);
        features.put(feature);
        FeatureCollection.put("type", "FeatureCollection");
        FeatureCollection.put("features", features);
        return FeatureCollection.toString();
    }
}
